﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BlazeNotes.Core;

namespace BlazeNotes
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Note _currentNote;

        public MainWindow()
        {
            InitializeComponent();

            OnRestoreClick(null, null);
        }

        private void OnSaveClick(object sender, RoutedEventArgs e)
        {
            using (var context = new DbNotesContext())
            {
                _currentNote.Content = SampleRichText.Document;
                context.Notes.Add(_currentNote);

                context.SaveChanges();
            }
        }

        private void OnRestoreClick(object sender, RoutedEventArgs e)
        {
            SampleRichText.Document.Blocks.Clear();

            using (var context = new DbNotesContext())
            {
                var note = context.Notes.OrderByDescending(order => order.Id).First();
                SampleRichText.Document = note.Content;
                _currentNote = note;
            }
        }
    }
}
